<%--
  Created by IntelliJ IDEA.
  User: 86135
  Date: 2024/11/27
  Time: 15:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>个人主页</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
        }
        .container {
            width: 80%;
            margin: 0 auto;
            text-align: center;
            background: #fff;
            padding: 20px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            border-radius: 8px;
            margin-top: 50px;
        }
        h1 {
            color: #333;
        }
        p {
            font-size: 18px;
            color: #666;
        }
        a {
            display: inline-block;
            margin-top: 20px;
            padding: 10px 20px;
            background: #007BFF;
            color: #fff;
            text-decoration: none;
            border-radius: 5px;
            transition: background 0.3s ease;
        }
        a:hover {
            background: #0056b3;
        }
        .change-password-button, .delete-user-button {
            display: inline-block;
            margin-top: 20px;
            padding: 10px 20px;
            border-radius: 5px;
            transition: background 0.3s ease;
        }
        .change-password-button {
            background: #28a745;
            color: #fff;
        }
        .change-password-button:hover {
            background: #218838;
        }
        .delete-user-button {
            background: #dc3545;
            color: #fff;
        }
        .delete-user-button:hover {
            background: #c82333;
        }
        .modal {
            display: none;
            position: fixed;
            z-index: 1;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            overflow: auto;
            background-color: rgba(0, 0, 0, 0.4);
        }
        .modal-content {
            background-color: #fefefe;
            margin: 15% auto;
            padding: 20px;
            border: 1px solid #888;
            width: 80%;
            max-width: 500px;
            border-radius: 8px;
        }
        .close {
            color: #aaa;
            float: right;
            font-size: 28px;
            font-weight: bold;
        }
        .close:hover,
        .close:focus {
            color: black;
            text-decoration: none;
            cursor: pointer;
        }
    </style>
</head>
<body>
<div class="container">
    <h1>个人主页</h1>
    <p>个人id: ${id}</p>
    <p>昵称: ${name}</p>
    <p>个人信息: ${user_information}</p>
    <a href="${pageContext.request.contextPath}/login">返回登录</a>
    <button class="change-password-button" onclick="openModal()">修改密码</button>
    <button class="delete-user-button" onclick="deleteUser(${id})">注销用户</button>
</div>

<!-- 修改密码模态框 -->
<div id="myModal" class="modal">
    <div class="modal-content">
        <span class="close" onclick="closeModal()">&times;</span>
        <h2>修改密码</h2>
        <form action="${pageContext.request.contextPath}/updatePassword" method="post">
            <input type="hidden" name="userId" value="${id}">
            <label for="currentPassword">当前密码:</label>
            <input type="password" id="currentPassword" name="currentPassword" required><br><br>
            <label for="newPassword">新密码:</label>
            <input type="password" id="newPassword" name="newPassword" required><br><br>
            <label for="confirmPassword">确认新密码:</label>
            <input type="password" id="confirmPassword" name="confirmPassword" required><br><br>
            <input type="submit" value="提交">
        </form>
    </div>
</div>

<script>
    function openModal() {
        document.getElementById('myModal').style.display = 'block';
    }

    function closeModal() {
        document.getElementById('myModal').style.display = 'none';
    }

    function deleteUser(userId) {
        if (confirm("确定要注销用户吗？")) {
            const form = document.createElement('form');
            form.method = 'POST';
            form.action = '${pageContext.request.contextPath}/deleteUser';
            form.style.display = 'none';

            const userIdInput = document.createElement('input');
            userIdInput.type = 'hidden';
            userIdInput.name = 'userId';
            userIdInput.value = userId;

            form.appendChild(userIdInput);
            document.body.appendChild(form);
            form.submit();
        }
    }
</script>
</body>
</html>